package com.geely.club.util.common;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;

/**
 * Created by mengyangyang on 2015-10-15.
 */
public class Animations {
    public static LayoutAnimationController getWaterfallAnimation() {
        TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
        AnimationSet set = new AnimationSet(true);
        set.addAnimation(translateAnimation);
        set.addAnimation(alphaAnimation);
        set.setDuration(50);
        LayoutAnimationController controller = new LayoutAnimationController(set);
        return controller;
    }

    public static Animation getShrinkAnimation() {
        ScaleAnimation a = new ScaleAnimation(1, 0, 1, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        a.setDuration(250);
        return a;
    }

    public static Animation getShakeAnimation() {
        TranslateAnimation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, -6, Animation.ABSOLUTE, +6, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
        translateAnimation.setRepeatCount(8);
        translateAnimation.setDuration(50);
        return translateAnimation;
    }

    public static Animation getBreathAnimation() {
        ScaleAnimation scaleAnimation = new ScaleAnimation(1, 1.2f, 1, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setRepeatCount(Animation.INFINITE);
        scaleAnimation.setDuration(200);
        scaleAnimation.setRepeatMode(Animation.REVERSE);
        return scaleAnimation;
    }

    public static AlphaAnimation getFadeInAnimation() {
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setDuration(300);
        return alphaAnimation;
    }
}
